<template>
	<view>
		<view class="mt-5" v-if="u_loadmore">
			<u-loadmore status="loading" icon-type="circle" />
		</view>
		<view v-else>
			<view class="" v-for="(item,index) in addArray" :key="index">
				<view class="m-2 d-flex j-sb a-center" >
					<view class="py-4 span-9 text-center bg-white rounded-10">{{item.full_amount}}</view>
					<view class="py-4 span-9 text-center bg-white rounded-10">{{item.reduce_amount}}</view>
					<image class="icon_delete" src="../../static/images/goods/icon_delete.png" mode="" @click="del(indexs)"></image>
				</view>
			</view>	
			<view class="m-2 d-flex j-sb  a-center">
				<view class="py-4 span-9 text-center bg-white rounded-10">
					<input type="digit" value="" placeholder="请设置满多少元" v-model="adlist.full_amount"/>
				</view>
				<view class="py-4 span-9 text-center bg-white rounded-10" >
					<input type="digit" value="" placeholder="立减多少元"  v-model="adlist.reduce_amount" />
				</view>
				<image @click="addList" class="icon_params_add" src="../../static/images/goods/icon_params_add.png" mode=""></image>
			</view>
			<view class="py-2 d-flex flex-column j-end  mr-2">
				<view class="d-flex j-end font-sm">购买数量达到阶梯数量时享受的优惠价格。</view>
			</view>
			
			<view class="rounded-20 m-2 pl-3 bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">是否设置为满减</view>
					<view class="d-flex j-center a-center">
						<u-switch v-model="full_reduction.is_fullcut" @change="full_switch" size="43"></u-switch>
					</view>
				</view>			
			</view>
			<view class="bg-white py-2 w-100 position-fixed bottom-0 btn">
				<button type="warn" @click="preserve ">保存</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked:false,
				adlist:{full_amount:"",reduce_amount:""},
				addArray:[],
				full_reduction:"", // 满减详情
				full_show:"yes", // 满减开关
				goods_id:"", // 商品ID
				u_loadmore:true, // 加载中
			}
		},
		methods: {
			// 添加
			addList(){
				if(!this.adlist.full_amount==""&&!this.adlist.reduce_amount==""){
					let arr={...this.adlist}
					this.addArray.push(arr)
					this.adlist = {full_amount:"",reduce_amount:""};
				}else{
					console.log("请输入内容")
				}
			},
			// 删除
			del(i){
				this.addArray.splice(i,1)
			},
			// 满减开关
			full_switch(e){
				if(this.full_reduction.is_fullcut){
					this.full_show="yes"
					console.log(this.full_show)
				}else{
					this.full_show="no"
					console.log(this.full_show)
				}
			},
			// 保存
			preserve(){
				this.$H.post("admin/merchant/goods/fullreduce/add",{
					goods_id:this.goods_id,
					is_full_reduce:this.full_show,
					full_reduction:this.addArray
				}).then(res=>{
					uni.navigateBack({
						delta:1
					})
					var globalData = getApp().globalData.full; //获取全局变量
					getApp().globalData.full= '满减'; //修改全局变量
				})	
			}
		},
		onLoad(e) {
			this.goods_id=e.goods_id
			this.$H.post("admin/merchant/goods/special/info",{goods_id:e.goods_id}).then(res=>{
				this.full_reduction=res.data
				this.addArray=res.data.full_reduction
				this.u_loadmore=false 
			})
		}
	}
</script>

<style>
	.btn /deep/ button{
		width: 85%;
		border-radius: 50upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
	}
	.icon_delete{
		width: 40upx;
		height: 40upx;
	}
	.icon_params_add{
		width: 40upx;
		height: 40upx;
	}
</style>
